#include "copycat.h"

int main( int argc, char *argv[] )
{
	if( argc != 4 )	{
		fprintf( stderr, "usage: %s  rule-cross-red  rule-rel-freq  out-file\n", argv[0] );
		return 1;
	}
	
	CRuleCross rule_cross;
	CRuleRF rule_rf;

	rule_cross.LoadRule( argv[1], 1 );
	rule_rf.LoadRule( argv[2], 0, 0.5 );


	fprintf( stderr, "cr: %d\n",  rule_cross.GetNumRules() );
	fprintf( stderr, "rf: %d\n",  rule_rf.GetNumRules() );

	CUTextFile out_file( argv[3], "w" );

	map<string, CRuleCross>::iterator itr = rule_cross.rule_map.begin();
	while( itr != rule_cross.rule_map.end() )	{
		CRuleCross cr = itr->second;
		string key_cr = string(cr.before.GetStr()) + string( "->" ) + string( cr.after.GetStr() );

		fprintf( out_file.GetFP(), "%s\t->\t%s\t%d\t", cr.before.GetStr(), cr.after.GetStr(), cr.before_cross - cr.after_cross );


		bool found = false;
		map<string, CRuleRF>::iterator itr2 = rule_rf.rule_map.begin();
		while( itr2 != rule_rf.rule_map.end() )	{
			CRuleRF rf = itr2->second;
			string key_rf = string(rf.before.GetStr() ) + string( "->" ) + string( rf.after.GetStr() );

			if( key_cr == key_rf )	{
				fprintf( out_file.GetFP(), "%1.4f\tMATCH\n", rf.prob );
				found = true;
				break;
			}

			itr2++;
		}

		if( found == false )	{
			fprintf( out_file.GetFP(), "-\n" );
		}


		itr++;
	};

	return 0;
}

